package com.janj.C3P0_Demo;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;

//C3P0 连接池的使用
public class Demo1 {
    public static void main(String[] args) throws Exception {
        //1.获取到连接池的对象 ds
        DataSource ds = new ComboPooledDataSource();

        //2.获取连接  conn
        Connection conn = ds.getConnection();

        //----------
        //3.获取执行者
        String sql = "UPDATE account SET money = money + 10000 where id = ? ";
        PreparedStatement ps = conn.prepareStatement(sql);

        //4.执行语句,增加的语句,每次给账户发10000元工资
          ps.setInt(1,1);
        int lineNumber = ps.executeUpdate();

        System.out.println("lineNumber = " + lineNumber);
        System.out.println(lineNumber>0?"发工资成功":"发工资失败");

        //5.释放资源
        ps.close();
        conn.close();
    }
}
